package naito_rescue.util.log;

import java.io.*;
import java.util.*;
import java.text.*;

public class GlobalLogger
{
	File logFile;
	PrintStream stream;
	GlobalLogLevel logLevel;
	
	private static GlobalLogger LOGGER = 
		new GlobalLogger();
		
	public static GlobalLogger getLogger(){
		return LOGGER;
	}
	
	public GlobalLogger(){
		SimpleDateFormat date = new SimpleDateFormat("yyyyMMddkkmmss");
		Date now = new Date();
		try {
		   logFile = new File("./logs" + date.format(now) + "__GlobalLog.log");
		   stream = new PrintStream(new FileOutputStream(logFile));
		} catch (Exception e) {
		   e.printStackTrace();
		}
		this.logLevel = GlobalLogLevel.INFO;
	}
	public void setLogLevel(GlobalLogLevel level){
		this.logLevel = level;
	}
	public void info(String context, String text){
		if(logLevel.level() > GlobalLogLevel.INFO.level()){
			return;
		}
		stream.println(" INFO:[" + context + "] " + text);
	}
	public void debug(String context, String text){
		if(logLevel.level() > GlobalLogLevel.DEBUG.level()){
			return;
		}
		stream.println("DEBUG:[" + context + "] ==> " + text);
	}
	public void trace(String context, String text){
		if(logLevel.level() > GlobalLogLevel.TRACE.level()){
			return;
		}
		stream.println("TRACE:[" + context + "] ====> " + text);
	}
	public enum GlobalLogLevel
	{
		NOTHING(Integer.MAX_VALUE),
		INFO(100),
		DEBUG(90),
		TRACE(80);
		private final int level;
		
		GlobalLogLevel(int level){
			this.level = level;
		}
		public int level(){
			return this.level;
		}
	}
}
